﻿using GeneralDashboard.ViewModel;
using ModernWpf.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GeneralDashboard.Pages
{
    /// <summary>
    /// UIDesignerDock.xaml 的交互逻辑
    /// </summary>
    public partial class UIDesignerDock : UserControl
    {
        public UIDesignerDock()
        {
            InitializeComponent();
            List<ControllViewModel> controls = new List<ControllViewModel>
            {
                new ControllViewModel { ControlType = "Label", Title = "标签"},
                new ControllViewModel { ControlType = "Button" ,Title = "按钮"},
                new ControllViewModel { ControlType = "Grid", Title = "折线图表"},
                new ControllViewModel { ControlType = "RadioButton", Title = "单选列表"},
                new ControllViewModel { ControlType = "Position", Title = "位姿状态"}
            };
            List<DataSourceViewModel> datasources = new List<DataSourceViewModel>
            {
                new DataSourceViewModel{ DataType = typeof(string), Source="串口1", Title="状态信息"},
                new DataSourceViewModel{ DataType = typeof(ulong), Source="串口1", Title="连接时间"},
                new DataSourceViewModel{ DataType = typeof(float), Source="Tcp源1", Title="经度"},
                new DataSourceViewModel{ DataType = typeof(float), Source="Tcp源1", Title="纬度"},
                new DataSourceViewModel{ DataType = typeof(double), Source="Udp源1", Title="前向加速度"},
                new DataSourceViewModel{ DataType = typeof(double), Source="串口2", Title="侧偏角"},
                new DataSourceViewModel{ DataType = typeof(double), Source="串口2", Title="俯仰角"},
                new DataSourceViewModel{ DataType = typeof(int), Source="串口1", Title="迭代次数"},
                new DataSourceViewModel{ DataType = typeof(float), Source="串口1", Title="经度"},
                new DataSourceViewModel{ DataType = typeof(float), Source="串口1", Title="纬度"},
                new DataSourceViewModel{ DataType = typeof(double), Source="Tcp源1", Title="旋转角"},
                new DataSourceViewModel{ DataType = typeof(byte), Source="Udp源1", Title="序列号"},
                new DataSourceViewModel{ DataType = typeof(string), Source="Udp源1", Title="用户ID"},
                new DataSourceViewModel{ DataType = typeof(bool), Source="Udp源1", Title="登录状态"},
            };

            ControlsList.ItemsSource = new ObservableCollection<ControllViewModel>(controls);
            DataList.ItemsSource = new ObservableCollection<DataSourceViewModel>(datasources);
        }
        private void GridViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            if (sender is GridViewItem)
            {
                GridViewItem draggedItem = sender as GridViewItem;
                DragDrop.DoDragDrop(draggedItem, draggedItem.DataContext, DragDropEffects.Copy);
                draggedItem.IsSelected = true;
            }
        }

        private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is ModernWpf.Controls.ListViewItem)
            {
                ModernWpf.Controls.ListViewItem draggedItem = sender as ModernWpf.Controls.ListViewItem;
                DragDrop.DoDragDrop(draggedItem, draggedItem.DataContext, DragDropEffects.Copy);
                draggedItem.IsSelected = true;
            }
        }
    }
}
